﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Util;
using UtilLibrary;

namespace Entity
{
    public class BizTask : BaseBizEntity
    {
        private string taskName; // 任务名称 

        public string TaskName
        {
            get { return taskName; }
            set { taskName = value; }
        }

        private String taskDescription; // 任务描述

        public String TaskDescription
        {
            get { return taskDescription; }
            set { taskDescription = value; }
        }

        private DateTime createDate; // 任务创建日

        public DateTime CreateDate
        {
            get { return createDate; }
            set { createDate = value; }
        }

        private DateTime planFinishDate; // 任务计划完成日期

        public DateTime PlanFinishDate
        {
            get { return planFinishDate; }
            set { planFinishDate = value; }
        }

        private DateTime realFinishDate; // 实际任务完成日期

        public DateTime RealFinishDate
        {
            get { return realFinishDate; }
            set { realFinishDate = value; }
        }

        private BizWorkflow taskWF; // 任务的工作流

        public BizWorkflow TaskWF
        {
            get { return taskWF; }
            set { taskWF = value; }
        }

        private int providerID; // 创建任务者ID

        public int ProviderID
        {
            get { return providerID; }
            set { providerID = value; }
        }

        private string providerName; // 创建任务者名称

        public string ProviderName
        {
            get { return providerName; }
            set { providerName = value; }
        }

        public int AssignerID
        {
            get {
                if (this.TaskStatus == TaskStatus.Holding)
                {
                    return 0;
                }
                if (this.TaskStatus == TaskStatus.Finish)
                    return this.ProviderID;

                return this.TaskWF.activeNode.EmpID;
            }
        }

        private String assignerName; // 任务指派人名称

        public String AssignerName
        {
            get { return assignerName; }
            set { assignerName = value; }
        }

        public int StepNo
        {
            get {
                if (this.TaskWF.activeNode != null)
                    return this.TaskWF.activeNode.StepNo;
                else
                    return 0;
            }    
        }

        public String StepName
        {
            get {
                if (this.TaskWF.activeNode != null)
                    return this.TaskWF.activeNode.StepName;
                else
                    return String.Empty;
            }
        }

        private TaskType type; // 任务类型

        public TaskType Type
        {
            get { return type; }
            set { type = value; }
        }

        private TaskStatus status; // 任务状态

        public TaskStatus TaskStatus
        {
            get { return status; }
            set { status = value; }
        }

        private ScheduleStatus evaluate; // 进度评估

        public ScheduleStatus Evaluate
        {
            get { return evaluate; }
            set { evaluate = value; }
        }

        public bool IsLastStep
        {
            get {
                return this.TaskWF.NodeCount == 0;
            }
        }

        public bool GoForward()
        {
            return TaskWF.SetNextActiveNode();
        }

        public void Finish()
        {
            this.TaskWF.Over();
            this.TaskStatus = TaskStatus.Finish;
            this.Evaluate = ScheduleStatus.Finish;
        }

        public override void SetEntityType()
        {
            this.dataEntityType = typeof(DAL.task);
        }
    }
}